#include <iostream>
// <cstring> 这个头文件是C语言中<string.h>头文件的C++版本，主要提供了一些操作C风格字符串（即以空字符 '\0' 结尾的字符数组）的函数和工具。
#include <cstring> 
#include <windows.h>
using namespace std;

int main()
{
    string s1 = "C++语言";
    string s2 = "程序设计";
    string s3 = s1 + s2;
    string s4;
    s4 = s1.append(s2); //会改变原字符串
    if (s3 == s4)
        cout << "结果相同" << endl;
    else
        cout << "结果不相同" << endl;

    int size = s1.size();
    int length = s1.length();
    // size() 和 length() 的作用相同
    cout << "size=" << size << ",length=" << length << endl;

    s1[0] = 'J';
    string s5 = s1.substr(3, 4);
    char str[20];
    strcpy(str, s5.c_str()); //  strcpy字符串复制， 此方法包含在头文件 cstring 中

    cout << "str=" << str << endl;           
    cout << "s1=" << s1 << ",s2=" << s2 << endl;

    s1.swap(s2); // 变量内容交换
    cout << "s1=" << s1 << ",s2=" << s2 << endl;
    cout << "str = " << str << endl;
    cout << "s2 = " << s2 << endl;
    cout << s2.find(str) << endl;

    system("pause");
    return 0;
}